package com.yugong.util;

import eu.bitwalker.useragentutils.UserAgent;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Component;

/**
 * 浏览器工具类
 *
 * @author yugong
 * @date 2024/1/2
 */
@Component
public class BrowserUtils {
    /**
     * 获取浏览器类型
     *
     * @param request HttpServletRequest请求对象
     * @return 浏览器类型
     */
    public String getBrowserType(HttpServletRequest request) {
        //获取浏览器信息
        return UserAgent
                .parseUserAgentString(request.getHeader("User-Agent"))
                .getBrowser()
                .getName();
    }

    /**
     * 获取浏览器版本
     *
     * @param request HttpServletRequest请求对象
     * @return 浏览器版本
     */
    public String getBrowserVersion(HttpServletRequest request) {
        return UserAgent
                .parseUserAgentString(request.getHeader("User-Agent"))
                .getBrowser()
                .getVersion(request.getHeader("User-Agent"))
                .getVersion();
    }
}